//
//  DetailHeader.m
//  夺宝吧
//
//  Created by xiaocai on 15/6/30.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "DetailHeader.h"
#import "WYADView.h"
#import "MiddleView.h"
#import "BuyNowView.h"
#import "ByGoOnView.h"
#import "WaitPublishView.h"
#import "WaitPublishLoginView.h"
#import "PublishingView.h"
#import "PublishingLoginView.h"
#import "PublishedView.h"
#import "PublishedLoginView.h"
#import "BuyNowView.h"
@interface DetailHeader ()
{
    //类型
    DetailType _currentType;
    //广告条banner
    WYADView *_adView;
    //中间固定不变的部分
    MiddleView *_middleView;
    //记录总高度
    CGFloat AllHeight;
}
@end
@implementation DetailHeader

//创建header的方法
-(instancetype)initWithType:(DetailType)typeDetail andPics:(NSArray *)pics andDetailDic:(NSDictionary *)dic pdcId:(NSString *)pdc_id SID:(NSString *)sid
{
    if (self = [super init]) {
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        _currentType = typeDetail;
        //记录总高度
        AllHeight = 0;
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Dbb_backColor"]];
        self.frame = CGRectMake(0, 0, WYMWITH, 180*app.autoSizeScaleY+190+180);
        if(typeDetail == typePublished||typeDetail == typePublishedLogin){
            self.frame = CGRectMake(0, 0, WYMWITH, 180*app.autoSizeScaleY+190+285);
        }
        //1
        _pdc_pics = pics;
        //广告条
        _adView =[[WYADView alloc]initWithFrame:CGRectMake(0, 0, WYMWITH, 180*app.autoSizeScaleY) AndPics:pics AndTitles:nil PicMode:UIViewContentModeScaleAspectFit];
        _adView.stopScrollFlag = YES;
        [_adView picOnClick:^(NSInteger index) {
            
        }];
        AllHeight += _adView.frame.size.height;
        [self addSubview:_adView];
        
        
        //2
        /*************变化部分*****************/
        switch (typeDetail) {
            case typeBuyNow:
            {
                BuyNowView *buyNowView = [[[NSBundle mainBundle]loadNibNamed:@"BuyNowView" owner:self options:nil]lastObject];
                buyNowView.frame = CGRectMake(0, AllHeight, WYMWITH,buyNowView.frame.size.height);
                AllHeight += (buyNowView.frame.size.height+10);
                [buyNowView fillViewWithDic:dic];
                [self addSubview:buyNowView];
            }
                break;
            case typeBuyContinue:
            {
                ByGoOnView *buyGoOnView = [[[NSBundle mainBundle]loadNibNamed:@"ByGoOnView" owner:self options:nil]lastObject];
                buyGoOnView.frame = CGRectMake(0, AllHeight, WYMWITH,buyGoOnView.frame.size.height);
                AllHeight += (buyGoOnView.frame.size.height+10);
                [buyGoOnView fillViewWithDic:dic];
                [self addSubview:buyGoOnView];
            }
                break;
            case typeWaitPublish:
            {
                WaitPublishView *waitPublishView = [[[NSBundle mainBundle]loadNibNamed:@"WaitPublishView" owner:self options:nil]lastObject];
                waitPublishView.frame = CGRectMake(0, AllHeight, WYMWITH,waitPublishView.frame.size.height);
                
                
                AllHeight += (waitPublishView.frame.size.height+10);
                [waitPublishView fillViewWithDic:dic];
                [self addSubview:waitPublishView];
            }
                break;
            case typeWaitPublishLogin:
            {
                WaitPublishLoginView *waitPublishView = [[[NSBundle mainBundle]loadNibNamed:@"WaitPublishLoginView" owner:self options:nil]lastObject];
                
                waitPublishView.frame = CGRectMake(0, AllHeight, WYMWITH,waitPublishView.frame.size.height);
                AllHeight += (waitPublishView.frame.size.height+10);
                [waitPublishView fillViewWithDic:dic];
                [self addSubview:waitPublishView];
            }
                break;
            case typePublishing:
            {
                PublishingView *publishingView = [[[NSBundle mainBundle]loadNibNamed:@"PublishingView" owner:self options:nil]lastObject];
                publishingView.frame = CGRectMake(0, AllHeight, WYMWITH,publishingView.frame.size.height);
                AllHeight += (publishingView.frame.size.height+10);
                [publishingView fillViewWithDic:dic];
                [self addSubview:publishingView];
            }
                break;
            case typePublishingLogin:
            {
                PublishingLoginView *waitPublishView = [[[NSBundle mainBundle]loadNibNamed:@"PublishingLoginView" owner:self options:nil]lastObject];
                waitPublishView.frame = CGRectMake(0, AllHeight, WYMWITH,waitPublishView.frame.size.height);
                AllHeight += (waitPublishView.frame.size.height+10);
                [waitPublishView fillViewWithDic:dic];
                [self addSubview:waitPublishView];
            }
                break;
            case typePublished:
            {
                PublishedView *publishedView = [[[NSBundle mainBundle]loadNibNamed:@"PublishedView" owner:self options:nil]lastObject];
                publishedView.frame = CGRectMake(0, AllHeight, WYMWITH,publishedView.frame.size.height);
                AllHeight += (publishedView.frame.size.height+10);
                [publishedView fillViewWithDic:dic];
                [self addSubview:publishedView];
            }
                break;
            case typePublishedLogin:
            {
                PublishedLoginView *publishedView = [[[NSBundle mainBundle]loadNibNamed:@"PublishedLoginView" owner:self options:nil]lastObject];
                publishedView.frame = CGRectMake(0, AllHeight, WYMWITH,publishedView.frame.size.height);
                AllHeight += (publishedView.frame.size.height+10);
                [publishedView fillViewWithDic:dic];
                [self addSubview:publishedView];
            }
                break;
            default:
                break;
        }

        
        //3
        //中间固定不变的部分
        _middleView = [[[NSBundle mainBundle]loadNibNamed:@"MiddleView" owner:self options:nil]lastObject];
        _middleView.frame = CGRectMake(0, AllHeight, WYMWITH, _middleView.frame.size.height);
        _middleView.pdc_id = pdc_id;
        _middleView.pdc_sid = sid;
        AllHeight += _middleView.frame.size.height;
        [self addSubview:_middleView];

    }
    
    return self;
}

//刷新表头
- (void)reloadTabHeaderWithDic:(NSDictionary *)dic  Type:(DetailType)type
{
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    _currentType = type;
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Dbb_backColor"]];
    if(type == typePublished||type == typePublishedLogin){
        self.frame = CGRectMake(0, 0, WYMWITH, 180*app.autoSizeScaleY+220+240);
        //2
        /*************变化部分*****************/
        switch (type) {
            case typePublished:
            {
                [_middleView removeFromSuperview];
                PublishedView *publishedView = [[[NSBundle mainBundle]loadNibNamed:@"PublishedView" owner:self options:nil]lastObject];
                publishedView.frame = CGRectMake(0, 180*app.autoSizeScaleY, WYMWITH,publishedView.frame.size.height);
                AllHeight += (publishedView.frame.size.height+10);
                [publishedView fillViewWithDic:dic];
                [self addSubview:publishedView];
                
                //3
                //中间固定不变的部分
                _middleView = [[[NSBundle mainBundle]loadNibNamed:@"MiddleView" owner:self options:nil]lastObject];
                _middleView.frame = CGRectMake(0, 180*app.autoSizeScaleY+publishedView.frame.size.height, WYMWITH, _middleView.frame.size.height);
                _middleView.pdc_id = self.pdc_id;
                [self addSubview:_middleView];
            }
                break;
            case typePublishedLogin:
            {
                [_middleView removeFromSuperview];
                PublishedLoginView *publishedView = [[[NSBundle mainBundle]loadNibNamed:@"PublishedLoginView" owner:self options:nil]lastObject];
                publishedView.frame = CGRectMake(0, 180*app.autoSizeScaleY+publishedView.frame.size.height, WYMWITH,publishedView.frame.size.height);
                AllHeight += (publishedView.frame.size.height+10);
                [publishedView fillViewWithDic:dic];
                [self addSubview:publishedView];
                
                //3
                //中间固定不变的部分
                _middleView = [[[NSBundle mainBundle]loadNibNamed:@"MiddleView" owner:self options:nil]lastObject];
                _middleView.frame = CGRectMake(0, 180*app.autoSizeScaleY+publishedView.frame.size.height, WYMWITH, _middleView.frame.size.height);
                _middleView.pdc_id = self.pdc_id;
                [self addSubview:_middleView];
            }
                break;
            default:
                break;
        }

    }
    
}
//刷新时间
- (void)updateTimelab:(NSString *)time
{
    [_middleView updateTimelab:time];
}
@end
